<template>
	<el-main>
		<el-card shadow="never" header="单位信息设置">
			<el-form :model="form" :rules="rules" ref="form" label-width="100px" status-icon>
				<el-form-item label="单位标识">
					<div v-html="form.orgId"></div>
				</el-form-item>
				<el-form-item label="单位名称" prop="orgName">
					<el-input v-model="form.orgName" clearable placeholder="单位名称" style="width: 300px"></el-input>
				</el-form-item>
				<el-form-item label="单位Logo">
					<sc-upload
						v-model="form.orgLogo"
						:apiObj="apiObj"
						title="Logo尺寸100*100"
						:limit="1"
						fit="contain"
					></sc-upload>
				</el-form-item>
				<el-form-item label="主题色">
					<el-color-picker v-model="form.themeColor" :predefine="predefineColors"></el-color-picker>
				</el-form-item>
				<el-form-item label="单位电话">
					<el-input v-model="form.orgTel" clearable placeholder="单位电话" style="width: 300px"></el-input>
				</el-form-item>
				<el-form-item label="单位传真">
					<el-input v-model="form.orgFax" clearable placeholder="单位传真" style="width: 300px"></el-input>
				</el-form-item>
				<el-form-item label="单位邮件">
					<el-input v-model="form.orgEmail" clearable placeholder="单位邮件" style="width: 300px"></el-input>
				</el-form-item>
				<el-form-item label="邮政编码">
					<el-input v-model="form.orgPost" clearable placeholder="邮政编码" style="width: 300px"></el-input>
				</el-form-item>
				<el-form-item label="单位地址">
					<el-input v-model="form.orgAdd" clearable placeholder="单位地址" style="width: 300px"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" :loading="isSaveing" @click="submit">保存</el-button>
				</el-form-item>
			</el-form>
		</el-card>
	</el-main>
</template>
<script>
export default {
	name: 'unit',
	data() {
		return {
			apiObj:this.$API.file.uploadLogo,
			form: {
				orgId: "8EADB678-A646-1E51-3E87-75A547B8AF19",
				orgName: "",
				themeColor: "",
				orgTel: "",
				orgFax: "",
				orgAdd: "",
				orgEmail: "",
				orgPost: "",
				orgLogo: ""
			},
			isSaveing: false,
			predefineColors: [
				'#ff4500',
				'#ff8c00',
				'#ffd700',
				'#67C23A',
				'#00ced1',
				'#409EFF',
				'#c71585'
			],
			rules: {
				orgName: [
					{required: true, message: '单位名称不能为空！'}
				]
			}
		}
	},
	mounted() {
		this.getUnit();
	},
	methods: {
		async getUnit() {
			var res = await this.$API.system.unit.getUnit.get();
			if (res.code == 200) {
				this.form = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		submit() {
			this.$refs.form.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.system.unit.update.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.visible = false;
						this.$message.success("保存成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		}
	}
}
</script>
